﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Text;
using OneSoft.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Net;

namespace BySoft.Web.Utility
{
    #region 常用控件样式
    public class ControlStyleConst
    {
        // textbox只读的Style
        public const string TextBoxOnlyReadStyle = "txtReadOnly";

        // 多行textbox只读的Style
        public const string MutiTextBoxOnlyReadStyle = "txtMutilReadOnly";

        // textbox的Style
        public const string TextBoxStyle = "txtStyle";

        // textbox的Style  130
        public const string Text130BoxStyle = "txt130ReadOnly";

        // textbox的RightStyle  130
        public const string TextBoxRightStyle = "txtRightStyle";

        // textbox只读的RightStyle  130
        public const string TextBoxRightReadOnly = "txtRightReadOnly";

        // 多行textbox的Style
        public const string MutiTextBoxStyle = "txtMutil";

        // Button的Style
        public const string ButtonStyle = "btnStyle";

        // ButtonEnable的Style
        public const string ButtonEnableStyle = "btnEnableStyle";

        // ButtonDelete的Style
        public const string ButtonDeleteStyle = "btnDelete";

        // leftButton的Style
        public const string leftButton = "btnLeft";

        // rightButton的Style
        public const string rightButton = "btnRight";

        // leftButtonEnable的Style
        public const string leftButtonEnable = "btnLeftEnable";

        // rightButtonDelete的Style
        public const string rightButtonDelete = "btnRightEnable";
    }
    #endregion

    public class UIHelper
    {
        /// <summary>
        /// 绑定SortedList到下拉框
        /// </summary>
        /// <param name="ddl"></param>
        /// <param name="sl"></param>
        public static void BindSortList(DropDownList ddl, SortedList sl)
        {
            ddl.Items.Clear();
            //ddl.Style.Add(HtmlTextWriterStyle.Width, "142px");
            ddl.DataSource = sl;
            ddl.DataTextField = "value";
            ddl.DataValueField = "key";
            ddl.DataBind();
        }

        /// <summary>
        /// 插入下拉框中“请选择”项
        /// </summary>
        /// <param name="ddl"></param>
        public static void InsertFirstItem(DropDownList ddl)
        {
            if (ddl.Items.Count == 0 || (ddl.Items.Count > 0 && ddl.Items[0].Text != "请选择..."))
            {
                ddl.Items.Insert(0, new ListItem("请选择...", ""));
            }
        }


        /// <summary>
        /// 当查询返回空数据时，显示Grid表头
        /// </summary>
        /// <param name="gv"></param>
        /// <param name="dt"></param>
        public static void BindEmptyGridView(GridView gv, DataTable dt)
        {
            gv.DataSource = null;
            gv.DataBind();
            if (gv.Rows.Count == 0)
            {
                dt.Rows.Add(dt.NewRow());
                dt.AcceptChanges();
                gv.DataSource = dt;
                gv.DataBind();
                if (gv.Rows.Count != 0)
                {
                    gv.Rows[0].Cells[0].Text = "";
                    gv.Rows[0].Style.Add(HtmlTextWriterStyle.Display, "none");
                }
                else
                {
                    gv.DataSource = null;
                    gv.DataBind();
                }
            }
        }

        /// <summary>
        /// 当查询返回空数据时，显示Grid表头
        /// </summary>
        /// <param name="gv"></param>
        /// <param name="dt"></param>
        public static void BindEmptyGridView(GridView gv, DataTable dt, string minValue)
        {
            gv.DataSource = null;
            gv.DataBind();
            if (gv.Rows.Count == 0)
            {
                dt.Rows.Add(dt.NewRow());
                dt.Rows[0][1] = minValue;
                dt.AcceptChanges();
                gv.DataSource = dt;
                gv.DataBind();
                gv.Rows[0].Cells[0].Text = "";
                gv.Rows[0].Style.Add(HtmlTextWriterStyle.Display, "none");
            }
        }



        #region MyRegion
        /// <summary>
        /// 从Html中提取出Text
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static string ExtractPlainTextWithLinefeedsOutOfHtml(string html)
        {
            string input = html;
            if ((input == null) && (input == string.Empty))
            {
                return input;
            }
            return Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(input, "[ \n]+", " ", RegexOptions.Multiline | RegexOptions.IgnoreCase), @"<script[^>]*>.*\?</script>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<br[^>]*>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p [^>]*>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</p [^>]*>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<hr>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), @"<!--.*\?-->", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</h2>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</h3>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</h4>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<table[^>]*>\r", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\r</table[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\r</tbody[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\r</tr[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\r</td[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\n ", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace("\r\n", "\r").Replace("\n", "\r").Replace("\r\r", "<p>").Replace("\r", "<br>");
        }

        /// <summary>
        /// 剔除Script标签
        /// </summary>
        /// <param name="dirtyText"></param>
        /// <returns></returns>
        public static string StripScriptTagsFromInput(string dirtyText)
        {
            return Regex.Replace(dirtyText, "<script((.|\n)*?)</script>", "&lt;!-- Inject Script Filtered --&gt;", RegexOptions.Multiline | RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 从Url中剔除机器名
        /// </summary>
        /// <param name="input"></param>
        /// <param name="servername"></param>
        /// <returns></returns>
        public static string RemoveServerNamesFromUrls(string input, string servername)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (servername == null)
            {
                throw new ArgumentNullException("servername");
            }
            StringBuilder builder = new StringBuilder("(href|src)\\s*=\\s*([\"']?)http(s?)://");
            foreach (char ch in servername)
            {
                builder.Append(@"\u");
                builder.Append(((int)ch).ToString("x").PadLeft(4, '0'));
            }
            builder.Append("/");
            Regex regex = new Regex(builder.ToString(), RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
            return regex.Replace(input, "$1=$2/");
        }

        /// <summary>
        /// 把Word转换为对应的HTML
        /// </summary>
        /// <param name="String_Word"></param>
        /// <returns></returns>
        public static string ConvertWordToHTML(string String_Word)
        {
            string input = String_Word;
            if ((input == null) && (input == string.Empty))
            {
                return input;
            }
            return Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(input, @"<\?xml[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), @"<span[^>]*><\/span[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), @"<span[^>]*><\/span[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<span><span>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), @"<\/span><\/span>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<script((.|\n)*?)</script>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<[^>]*>", "", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<br[^>]*>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p [^>]*>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</p [^>]*>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "</p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<hr>", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\n ", "\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "<p>", "\n\n", RegexOptions.Multiline | RegexOptions.IgnoreCase), "\n\n", "<p>"), "\n", "<br>");
        }

        /// <summary>
        /// 剔除绝对连接
        /// </summary>
        /// <param name="input"></param>
        /// <param name="abspath"></param>
        /// <returns></returns>
        public static string RemoveAbsolutelLinkPaths(string input, string abspath)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (abspath == null)
            {
                throw new ArgumentNullException("abspath");
            }
            if (!abspath.StartsWith("/"))
            {
                throw new ArgumentException("abspath must starts with '/'", "abspath");
            }
            abspath = abspath.Substring(0, abspath.LastIndexOf('/') + 1);
            StringBuilder builder = new StringBuilder("(href|src)\\s*=\\s*([\"']?)");
            foreach (char ch in abspath)
            {
                builder.Append(@"\u");
                builder.Append(((int)ch).ToString("x").PadLeft(4, '0'));
            }
            Regex regex = new Regex(builder.ToString(), RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
            return regex.Replace(input, "$1=$2");
        }

        /// <summary>
        /// 截字符串
        /// </summary>
        /// <param name="needCutString"></param>
        /// <param name="maxLength"></param>
        /// <returns></returns>
        public static string CutofString(string needCutString, int maxLength)
        {
            string result = needCutString;
            if (needCutString.Length > maxLength)
            {
                result = needCutString.Substring(0, maxLength - 3) + "...";

            }
            else
            {
                result = needCutString;
            }
            return result;
        }

        public static string RemoveLine(string line)
        {
            string result = string.Empty;
            if (!string.IsNullOrEmpty(line))
            {
                result = line.Substring(1);
            }
            return result;
        }
        #endregion

        #region 设置TextBox与DropdownList读写状态
        /// <summary>
        /// 设置TextBox与DropdownList读写状态
        /// </summary>
        /// <param name="container"></param>
        /// <param name="readOnly"></param>
        public static void SetControlStatus(Control container, bool readOnly)
        {
            foreach (Control ctl in container.Controls)
            {
                WebControl wctl = ctl as WebControl;
                if (wctl is TextBox)
                {
                    TextBox tb = wctl as TextBox;
                    tb.ReadOnly = readOnly;
                    tb.CssClass = "";
                    if (readOnly)
                    {
                        tb.CssClass = "";
                    }
                    //wctl.Enabled = 
                }
                else if (wctl is DropDownList)
                {
                    DropDownList ddl = wctl as DropDownList;
                    ddl.Enabled = !readOnly;
                }
                else
                {
                    if (ctl.Controls.Count > 0)
                        SetControlStatus(ctl, readOnly);
                }
            }
        }
        #endregion

        #region JavaScript 相关

        public static void Alert(object control, string strMsg)
        {
            AlertMessage(control, strMsg);
        }

        public static void AlertMessageGoToURL(object control, string message, string url)
        {
            ShowAlertGoToURL(control, message, url);
        }
        private static void ShowAlertGoToURL(object control, string message, string url)
        {
            //string str = "ShowAlertAndGotoUrl(\"提示 \",\"" + message + "\",\"" + url + "\");\n";
            string str = "ShowTopAlertAndGoToURL(\"提示 \",\"" + message + "\",\"" + url + "\");\n";
           

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowAlertAndGotoUrl", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowAlertAndGotoUrl", str, true);
            }
        }
        public static void AlertMessageGoToParentURL(object control, string message, string url)
        {
            ShowAlertGoToParentURL(control, message, url);
        }

        private static void ShowAlertGoToParentURL(object control, string message, string url)
        {
            //string str = "ShowAlertAndGotoUrl(\"提示 \",\"" + message + "\",\"" + url + "\");\n";
            string str = "ShowTopAlertAndGoToParentURL(\"提示 \",\"" + message + "\",\"" + url + "\");\n";


            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowTopAlertAndGotoParentUrl", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowTopAlertAndGotoParentUrl", str, true);
            }
        }

        public static void AlertMessage(object control, string message)
        {
            ShowAlert(control, message, "提示");
        }


        public static void AlertMessageAndRunScript(object control, string message, string script)
        {
            ShowAlertAndRunScript(control, message, script);
        }
        private static void ShowAlertAndRunScript(object control, string message, string script)
        {
            string str = "ShowTopAlertCallback('提示','" + message + "','" + script + "');";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowAlertAndRunScript", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowAlertAndRunScript", str, true);
            }
        }

        public static void RunScript(object control, string script)
        {
            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "RunScript", script, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "RunScript", script, true);
            }
        }

        private static void ShowAlert(object control, string message, string title)
        {

            //string str = "ShowAlert(\"" + title + "\",\"" + message + "\");\n";
            string str = " ShowTopAlert(\"" + title + "\",\"" + message + "\");\n";
            //string str = "$.messager.alert('" + message + "', 'The warning message');";  

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowAlert", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowAlert", str, true);

            }
        }

        public static void ShowDialogFrame(object control, string title, string url)
        {
            ShowDialogFrame(control, title, url, string.Empty, 600, 400);
        }
        public static void ShowDialogFrame(object control, string title, string url, int width, int height)
        {
            ShowDialogFrame(control, title, url, string.Empty, width, height);
        }
        public static void ShowDialogFrame(object control, string title, string url, string callback)
        {
            ShowDialogFrame(control, title, url, callback, 600, 400);
        }
        public static void ShowDialogFrame(object control, string title, string url, string callback, int width, int height)
        {
            RegsiterShowDialogFrame(control, title, BaseUrl + url, callback, width, height);
        }
        private static void RegsiterShowDialogFrame(object control, string title, string url, string callback, int width, int height)
        {
            string str = "ShowTopDialog(\"" + title + "\",\"" + url + "\",\"" + callback + "\",\"" + width + "\",\"" + height + "\");\n";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowTopDialog", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowTopDialog", str, true);

            }
        }
        public static void ParentFrameRedirect(object control, string url)
        {
            string str = "parent.window.location.href='" + url + "';\n";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ClientRedirect", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ClientRedirect", str, true);

            }
        }


        public static void CloseShowDialogFrame(object control)
        {
            string str = "CloseTopDialog();\n";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "CloseTopDialog", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "CloseTopDialog", str, true);

            }
        }
        public static void AlertAndCloseShowDialogFrame(object control, string message)
        {
            AlertAndCloseShowDialogFrame(control, "提示", message);
        }
        public static void AlertAndCloseShowDialogFrame(object control, string title, string message)
        {

            string str = "AlertAndCloseTopDialog(\"" + title + "\",\"" + message + "\");\n";
            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "AlertAndCloseTopDialog", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "AlertAndCloseTopDialog", str, true);

            }

        }
        //public static void ShowElementUseDailog(object control, string elementID, string callback, int width, int height)
        //{
        //    ShowElementUseDailog(control, "提示", elementID, callback, width, height);
        //}
        //public static void ShowElementUseDailog(object control, string title, string elementID, string callback, int width, int height)
        //{
        //    string str = "ShowElementUseDailog(\"" + title + "\",\"" + elementID + "\",\"" + callback + "\",\"" + width + "\",\"" + height + "\");\n";

        //    if (control is Page)
        //    {
        //        ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowElementUseDailog", str, true);

        //    }
        //    if (control is UpdatePanel)
        //    {
        //        ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowElementUseDailog", str, true);

        //    }

        //}


        public static void iframeAutoFit(object control)
        {

            //string str = "ShowAlert(\"" + title + "\",\"" + message + "\");\n";
            string str = " iframeAutoFit();";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "iframeAutoFi", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "iframeAutoFi", str, true);

            }
        }
        #endregion

        #region 添加UpdatePanel触发器
        /// <summary>
        /// Button
        /// </summary>
        public static void AppendButtonTrigger(UpdatePanel up, Button btn)
        {
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.ControlID = btn.UniqueID;
            trigger.EventName = "Click";
            up.Triggers.Add(trigger);
        }

        /// <summary>
        /// TextBox
        /// </summary>
        public static void AppendTextChangeTrigger(UpdatePanel up, TextBox tb)
        {
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.ControlID = tb.UniqueID;
            trigger.EventName = "TextChanged";
            up.Triggers.Add(trigger);
        }

        /// <summary>
        /// DropDownList
        /// </summary>
        public static void AppendTextChangeTrigger(UpdatePanel up, DropDownList ddl)
        {
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.ControlID = ddl.UniqueID;
            trigger.EventName = "TextChanged";
            up.Triggers.Add(trigger);
        }

        /// <summary>
        /// ListBox
        /// </summary>
        public static void AppendListBoxTrigger(UpdatePanel up, ListBox list)
        {
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.ControlID = list.UniqueID;
            trigger.EventName = "SelectedIndexChanged";
            up.Triggers.Add(trigger);
        }
        #endregion

        #region 绑定GridView时显示表头
        /// <summary>
        /// 绑定GridView时显示表头
        /// </summary>
        /// <param name="sgv"></param>
        public static void BindNullSGridView(SGridView sgv)
        {
            if (sgv != null)
            {
                if (sgv.DataSource != null
                  && sgv.DataSource is DataTable
                  && ((DataTable)(sgv.DataSource)).Rows.Count > 0)
                {
                    //todo nothing
                }
                else
                {
                    //在gridview的数据为空的情况下显示gird的title

                    sgv.AllowSorting = false;
                    DataTable dt = new DataTable();
                    DataRow dr = dt.NewRow();
                    dt.Rows.Add(dr);
                    sgv.DataSource = dt;
                    try
                    {
                        sgv.DataBind();//数据为空，此时会报错，但是grid的标题会显示出来
                    }
                    catch
                    {
                        if (sgv.Controls.Count == 1 && sgv.Controls[0].Controls.Count == 2)
                        {
                            sgv.Controls[0].Controls[1].Visible = false;
                        }

                    }

                    if (sgv.Rows.Count > 0)
                        sgv.Rows[0].Visible = false;

                }
            }

        }
        #endregion

        #region 给TextBox设置最大长度
        /// <summary>
        /// 给TextBox设置最大长度
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="maxLength"></param>
        public static void SetTextBoxLength(TextBox tb, int maxLength)
        {
            tb.Attributes.Add("onKeyUp", "CheckLength('" + tb.ClientID + "'," + maxLength.ToString() + ")");
        }
        #endregion

        #region Static AddShowDialog
        /// <summary>
        /// ImageButton
        /// </summary>
        public static void AddShowDialog(System.Web.UI.WebControls.ImageButton button, string strUrl, int intWidth, int intHeight)
        {
            string strScript = "";
            strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";
            strScript += "var strName ='';";
            if (strUrl.Substring(0, 1) == "/")
            {
                strUrl = strUrl.Substring(1, strUrl.Length - 1);
            }
            strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl;
            strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";
            button.Attributes.Add("onClick", strScript);
        }

        /// <summary>
        /// Button
        /// </summary>
        public static void AddShowDialog(System.Web.UI.WebControls.Button button, string strUrl, int intWidth, int intHeight)
        {
            string strScript = "";
            strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";
            strScript += "var strName ='';";
            if (strUrl.Substring(0, 1) == "/")
            {
                strUrl = strUrl.Substring(1, strUrl.Length - 1);
            }
            strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl;
            strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";
            button.Attributes.Add("onClick", strScript);
        }

        /// <summary>
        /// LinkButton
        /// </summary>
        public static void AddShowDialog(System.Web.UI.WebControls.LinkButton button, string strUrl, int intWidth, int intHeight)
        {
            string strScript = "";
            strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";
            strScript += "var strName ='';";
            if (strUrl.Substring(0, 1) == "/")
            {
                strUrl = strUrl.Substring(1, strUrl.Length - 1);
            }
            strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl;
            strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";
            button.Attributes.Add("onClick", strScript);
        }
        #endregion

        #region 设置TextBox是否只读
        /// <summary>
        /// TextBox
        /// </summary>
        /// <param name="tb">TextBox</param>
        /// <param name="ReadOnly">true/false</param>
        public static void SetTextBoxReadOnly(TextBox tb, bool ReadOnly)
        {
            if (ReadOnly)
            {
                tb.ReadOnly = true;
                tb.CssClass = ControlStyleConst.TextBoxOnlyReadStyle;
            }
            else
            {
                tb.ReadOnly = false;
                tb.CssClass = ControlStyleConst.TextBoxStyle;
            }
        }
        public static void SetTextBoxReadOnlyUseJs(TextBox tb, bool ReadOnly)
        {
            if (ReadOnly)
            {
                //tb.ReadOnly = true;
                tb.Attributes.Add("onkeydown", "return false;");
                tb.CssClass = ControlStyleConst.TextBoxOnlyReadStyle;
            }
            else
            {
                tb.Attributes.Remove("onkeydown");
                tb.CssClass = ControlStyleConst.TextBoxStyle;
            }
        }

        /// <summary>
        /// TextBox
        /// </summary>
        /// <param name="tb">TextBox</param>
        /// <param name="ReadOnly">true/false</param>
        public static void SetNTextBoxReadOnly(TextBox tb, bool ReadOnly)
        {
            if (ReadOnly)
            {
                tb.ReadOnly = true;
                tb.CssClass = ControlStyleConst.Text130BoxStyle;
            }
            else
            {
                tb.ReadOnly = false;
                tb.CssClass = ControlStyleConst.TextBoxStyle;
            }
        }
        public static void SetRTextBoxReadOnlyUseJs(TextBox tb, bool ReadOnly)
        {
            if (ReadOnly)
            {
                tb.Attributes.Add("onkeydown", "return false;");
                tb.CssClass = ControlStyleConst.TextBoxRightReadOnly;
            }
            else
            {
                tb.CssClass = ControlStyleConst.TextBoxRightStyle;
            }
        }
        /// <summary>
        /// MutiTextBox
        /// </summary>
        /// <param name="tb">TextBox</param>
        /// <param name="ReadOnly">true/false</param>
        public static void SetMutiTextBoxReadOnly(TextBox tb, bool ReadOnly)
        {
            if (ReadOnly)
            {
                tb.ReadOnly = true;
                tb.CssClass = ControlStyleConst.MutiTextBoxOnlyReadStyle;
            }
            else
            {
                tb.ReadOnly = false;
                tb.CssClass = ControlStyleConst.MutiTextBoxStyle;
            }
        }
        #endregion

        #region 设置Button的Enable
        /// <summary>
        /// Button
        /// </summary>
        /// <param name="tb">Button</param>
        /// <param name="Enable">true/false</param>
        public static void SetButtonEnable(Button btn, bool Enable)
        {
            if (Enable)
            {
                btn.Enabled = true;
                btn.CssClass = ControlStyleConst.ButtonStyle;
            }
            else
            {
                btn.Enabled = false;
                btn.CssClass = ControlStyleConst.ButtonEnableStyle;
            }
        }

        /// <summary>
        /// 向右按钮
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="Enable"></param>
        public static void SetButtonLeftEnable(Button btn, bool Enable)
        {
            if (Enable)
            {
                btn.Enabled = true;
                btn.CssClass = ControlStyleConst.leftButton;
            }
            else
            {
                btn.Enabled = false;
                btn.CssClass = ControlStyleConst.leftButtonEnable;
            }
        }
        /// <summary>
        /// 向左按钮
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="Enable"></param>
        public static void SetButtonRightEnable(Button btn, bool Enable)
        {
            if (Enable)
            {
                btn.Enabled = true;
                btn.CssClass = ControlStyleConst.rightButton;
            }
            else
            {
                btn.Enabled = false;
                btn.CssClass = ControlStyleConst.rightButtonDelete;
            }
        }
        #endregion

        #region The base url of application
        /// <summary>
        /// The base url of application
        /// </summary>
        public static string BaseUrl
        {
            get
            {
                string strBaseUrl = "";
                strBaseUrl += "http://" + HttpContext.Current.Request.Url.Host;
                if (HttpContext.Current.Request.Url.Port.ToString() != "80")
                {
                    strBaseUrl += ":" + HttpContext.Current.Request.Url.Port;
                }
                strBaseUrl += HttpContext.Current.Request.ApplicationPath;
                if (HttpContext.Current.Request.ApplicationPath[HttpContext.Current.Request.ApplicationPath.Length - 1] != '/')
                {
                    strBaseUrl += "/";
                }
                return strBaseUrl;
            }
        }
        #endregion


        /// <summary>
        /// 获取客户端IP地址
        /// </summary>
        /// <returns></returns>
        public static string GetIP()
        {
            string result = String.Empty;
            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            if (string.IsNullOrEmpty(result) || !IsIP(result))
            {
                return "0.0.0.0";
            }
            //result = Dns.Resolve(Dns.GetHostName()).AddressList[0].ToString();
            return result;
        }

        /// <summary>
        /// 是否为ip
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static bool IsIP(string ip)
        {
            return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
        }


        public static String GetQueryStringValue(String paramName)
        {
            return HttpContext.Current.Request.QueryString[paramName] == null ? "" : HttpContext.Current.Request.QueryString[paramName];
        }

        public static int GetQueryIntValue(String paramName)
        {
            if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString[paramName]))
            {
                HttpContext.Current.Response.Write(String.Format(@"没有传入""{0}""参数！", paramName));
                HttpContext.Current.Response.End();
                return 0;
            }

            Int32 ret;

            if (Int32.TryParse(HttpContext.Current.Request.QueryString[paramName].ToString(), out ret))
            {
                return ret;
            }

            HttpContext.Current.Response.Write(String.Format(@"参数""{0}""格式不正确！", paramName));
            HttpContext.Current.Response.End();
            return 0;
        }


        /// <summary>
        ///  把试剂读数格式化UI上需要的格式
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string FormatReagent(decimal data)
        {
            string result = data.ToString();
            int index = result.IndexOf('.');
            if (index > 0)
            {
                result = result.Substring(0, index);
            }
            return result;
        }


        public static void ShowDialog(object control, string url, int width, int height)
        {
            string str = "window.showModalDialog(\"" + url + "\",\"dialogWidth=" + width + "px\",\"dialogHeight=" + height + "px\");";

            if (control is Page)
            {
                ScriptManager.RegisterStartupScript((Page)control, control.GetType(), "ShowDialog", str, true);

            }
            if (control is UpdatePanel)
            {
                ScriptManager.RegisterStartupScript((UpdatePanel)control, control.GetType(), "ShowDialog", str, true);

            }
        }
        private static bool IsEquGroupRows(GridViewRow gvr, GridViewRow gvrNext, string[] strs)
        {
            bool bEqu = true;
            foreach (string item in strs)
            {
                Label lblpre = gvr.FindControl(item) as Label;
                Label lblnext = gvrNext.FindControl(item) as Label;
                if (lblpre.Text != lblnext.Text || string.IsNullOrEmpty(lblnext.Text))
                {
                    bEqu = false;
                    break;
                }
            }
            
            return bEqu;
        }

        public static void GroupRows(GridView gvResult, string[] strs, int[] MerCols)
        {
            //参考列必须要有
            if (strs == null || strs.Length < 1)
            {
                return;
            }
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    bool bEqu = IsEquGroupRows(gvr, gvrNext, strs);
                    if (bEqu)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }

        public static void GroupRows(GridView gvResult, string strBaseColName, int[] MerCols)
        {
            //参考列必须要有
            if (string.IsNullOrEmpty(strBaseColName))
            {
                return;
            }
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    bool bEqu = true;
                    Label lblpre = gvr.FindControl(strBaseColName) as Label;
                    Label lblnext = gvrNext.FindControl(strBaseColName) as Label;
                    if (lblpre.Text != lblnext.Text || string.IsNullOrEmpty(lblnext.Text))
                    {
                        bEqu = false;
                    }
                    if (bEqu)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }

        public static void GroupRows(GridView gvResult, int[] MerCols)
        {
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    if (gvr.Cells[0].Text == gvrNext.Cells[0].Text)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }
        public static void GroupRows1(GridView gvResult, int[] MerCols)
        {
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    if (gvr.Cells[1].Text == gvrNext.Cells[1].Text)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }

        public static void GroupRowsLevel1(GridView gvResult, int[] MerCols)
        {
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    if (gvr.Cells[0].Text == gvrNext.Cells[0].Text)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }

        public static void GroupRowsLevel2(GridView gvResult, int[] MerCols)
        {
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    if (gvr.Cells[1].Text == gvrNext.Cells[1].Text)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }

        public static void GroupRowsLevel3(GridView gvResult, int[] MerCols)
        {
            int i = 0, rowSpanNum = 1, ji = 1;
            int start = 0;
            while (i < gvResult.Rows.Count - 1)
            {
                GridViewRow gvr = gvResult.Rows[i];

                for (++i; i < gvResult.Rows.Count; i++)
                {
                    GridViewRow gvrNext = gvResult.Rows[i];
                    if (gvr.Cells[2].Text == gvrNext.Cells[2].Text)
                    {
                        foreach (int j in MerCols)
                        {
                            gvrNext.Cells[j].Visible = false;
                        }
                        rowSpanNum++;
                    }
                    else
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        rowSpanNum = 1;
                        //ji = ji + 1;
                        break;
                    }

                    if (i == gvResult.Rows.Count - 1)
                    {
                        foreach (int j in MerCols)
                        {
                            gvr.Cells[j].RowSpan = rowSpanNum;
                        }
                        //ji = ji + 1;
                    }
                }
                if (ji % 2 == 1)
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = Color.White;
                    }
                }
                else
                {
                    for (; start < i; start++)
                    {
                        gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                    }
                }
                start = i;
                ji = ji + 1;
            }

            if (ji % 2 == 1)
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = Color.White;
                }
            }
            else
            {
                for (; start <= gvResult.Rows.Count - 1; start++)
                {
                    gvResult.Rows[start].BackColor = gvResult.AlternatingRowStyle.BackColor;
                }
            }
        }


        //c#的中英文混合字符串截取指定长度,startidx从0开始
        public static bool IsChinese(char c)
        {
            return (int)c >= 0x4E00 && (int)c <= 0x9FA5;
        }
        //获得字节长度
        private static int getLengthb(string str)
        {
            return System.Text.Encoding.Default.GetByteCount(str);
        }
        public static string GetStrLenBWithoutHtml(string str, int len)
        {
            str = checkStr(str);
            int startidx = 0;
            int Lengthb = getLengthb(str);
            if (startidx + 1 > Lengthb)
            {
                return "";
            }
            int j = 0;
            int l = 0;
            int strw = 0;//字符的宽度
            bool b = false;
            string rstr = "";
            for (int i = 0; i < str.Length; i++)
            {
                char c = str[i];
                if (j >= startidx)
                {
                    rstr = rstr + c;
                    b = true;
                }
                if (IsChinese(c))
                {
                    strw = 2;
                }
                else
                {
                    strw = 1;
                }
                j = j + strw;
                if (b)
                {
                    l = l + strw;
                    if ((l + 1) >= len) break;

                }


            }
            return rstr;
        }
        private static string checkStr(string html)
        {
            System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);


            System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html = regex1.Replace(html, ""); //过滤<script></script>标记 
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 网管网bitsCN.com 
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 
            html = regex4.Replace(html, ""); //过滤iframe 
            html = regex5.Replace(html, ""); //过滤frameset 
            html = regex6.Replace(html, ""); //过滤frameset 
            html = regex7.Replace(html, ""); //过滤frameset 
            html = regex8.Replace(html, ""); //过滤frameset 
            html = regex9.Replace(html, "");
            html = html.Replace(" ", "");


            html = html.Replace("</strong>", "");
            html = html.Replace("<strong>", "");
            return html.Replace("&nbsp;", "");
        }
    }
}
